
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
	<link rel=stylesheet href='include/hoj.css' type='text/css'>
</head>
<body>
<center>
<div style="width:90%; text-align:left">
<img src="image/logo.png"/>
</div>
<table width=96%> 
	<tr align="center" class='hd' valign="top">
				<th><a href="faqs.php">F.A.Qs</a></th>
		<th><a href="./bbs.php">Web Board</a></th>
		<th><a href="./">Home</a></th>
		<th><a href="./problemset.html">ProblemSet</a></th>
		<th><a href="./status.php">Status</a></th>
		<th><a href="./ranklist.php">Ranklist</a></th>
		<th><a href="./contest.php">Contest</a></th>
		<th><a href=loginpage.php>Login</a></th><th><a href=registerpage.php>Register</a></th>	</tr>
</table>
</center>
<center>
<div class="notice">
	<div>
		<B>Notice:</B>鉴于种种原因，本OJ自下周星期一（3月5号）开始不再全面开放，请各位做好善后事宜，谢谢合作。	</div>
</div>
</center>
</div>
<title>Problem 1647. -- [Usaco2007 Open]Fliptile -- 衡阳八中OJ离线版-2012-02-29</title><center><h2>1647: [Usaco2007 Open]Fliptile</h2><span class=green>Time Limit: </span>5 Sec&nbsp;&nbsp;<span class=green>Memory Limit: </span>64 MB<br><span class=green>Submit: </span>156&nbsp;&nbsp;<span class=green>Solved: </span>62<br>[<a href='submitpage.php?id=1647'>Submit</a>][<a href='problemstatus.php?id=1647'>Status</a>][<a href='bbs.php?id=1647'>Discuss</a>]</center><h2>Description</h2><div class=content><p><span style="font-size: medium">Farmer John knows that an intellectually satisfied cow is a happy cow who will give more milk. He has arranged a brainy activity for cows in which they manipulate an M x N grid (1 &lt;= M &lt;= 15; 1 &lt;= N &lt;= 15) of square tiles, each of which is colored black on one side and white on the other side. As one would guess, when a single white tile is flipped, it changes to black; when a single black tile is flipped, it changes to white. The cows are rewarded when they flip the tiles so that each tile has the white side face up. However, the cows have rather large hooves and when they try to flip a certain tile, they also flip all the adjacent tiles (tiles that share a full edge with the flipped tile). Since the flips are tiring, the cows want to minimize the number of flips they have to make. Help the cows determine the minimum number of flips required, and the locations to flip to achieve that minimum. If there are multiple ways to achieve the task with the minimum amount of flips, return the one with the least lexicographical ordering in the output when considered as a string. If the task is impossible, print one line with the word &quot;IMPOSSIBLE&quot;. </span></p>
<p></p>
<p><span style="font-size: medium">选择一个格子，翻动本身和上下左右范围内的5个格，为怎样翻动才能翻成全为0的状态。要求输出在翻动最小次改写的提供下，翻动方式（1是翻动，0是不翻动）且按字典序排列最靠前的那个。</span></p></div><h2>Input</h2><div class=content><p>* Line 1: Two space-separated integers: M and N * Lines 2..M+1: Line i+1 describes the colors (left to right) of row i of the grid with N space-separated integers which are 1 for black and 0 for white</p></div><h2>Output</h2><div class=content><p>* Lines 1..M: Each line contains N space-separated integers, each specifying how many times to flip that particular location.</p></div><h2>Sample Input</h2>
			<div class=content><span class=sampledata>4 4<br />
1 0 0 1<br />
0 1 1 0<br />
0 1 1 0<br />
1 0 0 1<br />
<br />
<br />
</span></div><h2>Sample Output</h2>
			<div class=content><span class=sampledata>0 0 0 0<br />
1 0 0 1<br />
1 0 0 1<br />
0 0 0 0<br />
<br />
OUTPUT DETAILS:<br />
<br />
After flipping at row 2 column 1, the board will look like:<br />
0 0 0 1<br />
1 0 1 0<br />
1 1 1 0<br />
1 0 0 1<br />
<br />
After flipping at row 2 column 4, the board will look like:<br />
0 0 0 0<br />
1 0 0 1<br />
1 1 1 1<br />
1 0 0 1<br />
<br />
After flipping at row 3 column 1, the board will look like:<br />
0 0 0 0<br />
0 0 0 1<br />
0 0 1 1<br />
0 0 0 1<br />
<br />
After flipping at row 3 column 4, the board will look like:<br />
0 0 0 0<br />
0 0 0 0<br />
0 0 0 0<br />
0 0 0 0<br />
<br />
Another solution might be:<br />
0 1 1 0<br />
0 0 0 0<br />
0 0 0 0<br />
0 1 1 0<br />
but this solution is lexicographically higher than the solution above.<br />
</span></div><h2>HINT</h2>
			<div class=content><p></p></div><h2>Source</h2>
			<div class=content><p><a href='problemset.html?search=Silver'>Silver</a></p></div><center>[<a href='submitpage.php?id=1647'>Submit</a>][<a href='problemstatus.php?id=1647'>Status</a>][<a href='bbs.php?id=1647'>Discuss</a>]</center>﻿<br>

<a href="./"><span class=red>HOME</span></a>
<a href="javascript:history.go(-1)"><span class=red>Back</span></a>

<hr>
<center>
	<div class="footer">
			<a href=setlang.php?lang=ko>한국어</a>&nbsp;
		<a href=setlang.php?lang=cn>中文</a>&nbsp;
		<a href=setlang.php?lang=fa>فارسی</a>&nbsp;
		<a href=setlang.php?lang=en>English</a>&nbsp;
		<a href=setlang.php?lang=th>ไทย</a>
	<br>		<div>版权所有 &copy;2008-2012 WaterPark Organization. | <script src="http://s21.cnzz.com/stat.php?id=2982771&web_id=2982771" language="JavaScript"></script>
</div>
		<div>Based on opensource project <a href="http://hustoj.googlecode.com">hustoj</a>.</div>
	</div>
</center>
</body>
</html>
